Given('a connection to IRC') do
  IRC.connect
end

Given('a websocket connection') do
  WebSocketHelper.connect
end

Given('that the messages cache is empty') do
  WebSocketHelper.clear_cache
end

Given('that we have joined {string}') do | channel |
  IRC.join(channel)
end

When('we join {string}') do | channel |
  IRC.join channel
end

When('we wait a bit') do
  sleep 2
end

When('we send an IRC message to {string} saying {string}') do | channel, message |
  IRC.send_message(channel, message)
end

When('we disconnect from IRC') do
  IRC.quit
end

When('we request a user list') do
end

Then('the movienight websocket sends a message announcing that {string} has joined') do | user |
  msgs = WebSocketHelper.messages.select { | x | x["Type"] == 3 and x["Data"]["User"] ==  user }
  expect(msgs.length).to eq(1)
end

Then('the movienight websocket sends a message announcing that {string} has left') do | user |
  #TODO
end

Then('the movienight websocket sends a message announcing a chat message saying {string}') do | message |
  #TODO
end

Then('the following users should be listed:') do | users |
  #TODO
end
